// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { rankItemType } from "../../game/gameType";
import { ListItem } from "../../util/ListView/ListItem";
import { ccs } from "../../util/services";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<rankItemType> {

    @property(cc.Label)
    playerName: cc.Label = null;

    @property(cc.Label)
    money: cc.Label = null;

    @property(cc.Label)
    child: cc.Label = null;
    
    @property(cc.Label)
    monthIncome: cc.Label = null;

    @property(cc.Label)
    work: cc.Label = null;

    @property(cc.Label)
    age: cc.Label = null;

    @property(cc.Label)
    rankIndex: cc.Label = null;

    initItem(data: rankItemType, index?: number) {
        //初始化
        this.playerName.string = data.name;
        this.money.string = ccs.gf.getOmitNum(data.money);
        this.monthIncome.string = ccs.gf.getOmitNum(data.monthIncome);
        // this.child.string = ccs.gf.getOmitNum(data.child);
        this.work.string = data.work;
        this.age.string = data.age + "";
        if(index > -1) {
            this.rankIndex.string = index + 1 + "";
        }
        if(index == 0) {
            this.rankIndex.node.color = cc.color(244,239,14)
        }else if(index == 1){
            this.rankIndex.node.color = cc.color(183,142,75)
        }else if(index == 2){
            this.rankIndex.node.color = cc.color(220,128,35)
            
        }
    }
    onItemclick(data: rankItemType) {

    }
    start () {
        this.node.on('on_scroll_view', (msg) => {
            this.node.opacity = msg;
          });
    }
}
